package net.melon.sso.inst.ssh.web;

import java.util.List;

import javax.annotation.Resource;

import net.esj.basic.core.engine.util.enumeration.EnumProvidersFactory;
import net.esj.basic.exception.MelonException;
import net.esj.basic.pojo.EnumStructure;
import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.sso.SSOConstants.MemberState;
import net.melon.sso.pojo.Config;
import net.melon.sso.pojo.Member;
import net.melon.sso.pojo.MemberExtra;
import net.melon.sso.pojo.MemberType;
import net.melon.sso.service.SSOManage;

public class MemberAction extends AbstractPluginPageAction<Member, Member>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8649224051188914154L;
	
	@Resource
	private EnumProvidersFactory enumProvidersFactory;
	
	@Resource
	private SSOManage ssoManage;
	
	private List<MemberExtra> extralist;

	@Override
	public void doAdd() throws MelonException {
		if(extralist!=null){
			ssoManage.saveMember(entity);
		}else{
			ssoManage.saveMember(entity);
		}
	}
	
	@Override
	protected void doGetEntity() {
		entity = ssoManage.getMember(id, true);
	}
	
	@Override
	protected void doUpdate() throws Exception {
		ssoManage.updateMember(entity);
	}
	public List<MemberType> getTypes(){
		return ssoManage.listMemberType();
	}
	
	public MemberState[] getStates(){
		return MemberState.values();
	}
	
	public List<EnumStructure> getSexs(){
		return enumProvidersFactory.findEnum("SEX");
	}
	
	public List<EnumStructure> getSizes(){
		return enumProvidersFactory.findEnum("SIZE");
	}
	
	public List<Config> getExtras(){
		return ssoManage.getExtras();
	}
	
	public void setEntity(Member entity){
		this.entity = entity;
	}
	
	public Member getEntity(){
		return entity;
	}

	public List<MemberExtra> getExtralist() {
		return extralist;
	}

	public void setExtralist(List<MemberExtra> extralist) {
		this.extralist = extralist;
	}
	
}
